<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE GeneralizedNewtypeDeriving #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE LambdaCase #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Llvm.MetaData</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-5"></span><span>
</span><span id="line-6"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-7"></span><span>
</span><span id="line-8"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Llvm.Types.html"><span class="hs-identifier">GHC.Llvm.Types</span></a></span><span>
</span><span id="line-9"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-10"></span><span>
</span><span id="line-11"></span><span class="hs-comment">-- The LLVM Metadata System.</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- The LLVM metadata feature is poorly documented but roughly follows the</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- following design:</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- - Metadata can be constructed in a few different ways (See below).</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- - After which it can either be attached to LLVM statements to pass along</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- extra information to the optimizer and code generator OR specifically named</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- metadata has an affect on the whole module (i.e., linking behaviour).</span><span>
</span><span id="line-19"></span><span class="hs-comment">--</span><span>
</span><span id="line-20"></span><span class="hs-comment">--</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- # Constructing metadata</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- Metadata comes largely in three forms:</span><span>
</span><span id="line-23"></span><span class="hs-comment">--</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- - Metadata expressions -- these are the raw metadata values that encode</span><span>
</span><span id="line-25"></span><span class="hs-comment">--   information. They consist of metadata strings, metadata nodes, regular</span><span>
</span><span id="line-26"></span><span class="hs-comment">--   LLVM values (both literals and references to global variables) and</span><span>
</span><span id="line-27"></span><span class="hs-comment">--   metadata expressions (i.e., recursive data type). Some examples:</span><span>
</span><span id="line-28"></span><span class="hs-comment">--     !{ !&quot;hello&quot;, !0, i32 0 }</span><span>
</span><span id="line-29"></span><span class="hs-comment">--     !{ !1, !{ i32 0 } }</span><span>
</span><span id="line-30"></span><span class="hs-comment">--</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- - Metadata nodes -- global metadata variables that attach a metadata</span><span>
</span><span id="line-32"></span><span class="hs-comment">--   expression to a number. For example:</span><span>
</span><span id="line-33"></span><span class="hs-comment">--     !0 = !{ [&lt;metadata expressions&gt;] !}</span><span>
</span><span id="line-34"></span><span class="hs-comment">--</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- - Named metadata -- global metadata variables that attach a metadata nodes</span><span>
</span><span id="line-36"></span><span class="hs-comment">--   to a name. Used ONLY to communicated module level information to LLVM</span><span>
</span><span id="line-37"></span><span class="hs-comment">--   through a meaningful name. For example:</span><span>
</span><span id="line-38"></span><span class="hs-comment">--     !llvm.module.linkage = !{ !0, !1 }</span><span>
</span><span id="line-39"></span><span class="hs-comment">--</span><span>
</span><span id="line-40"></span><span class="hs-comment">--</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- # Using Metadata</span><span>
</span><span id="line-42"></span><span class="hs-comment">-- Using metadata depends on the form it is in:</span><span>
</span><span id="line-43"></span><span class="hs-comment">--</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- - Attach to instructions -- metadata can be attached to LLVM instructions</span><span>
</span><span id="line-45"></span><span class="hs-comment">--   using a specific reference as follows:</span><span>
</span><span id="line-46"></span><span class="hs-comment">--     %l = load i32* @glob, !nontemporal !10</span><span>
</span><span id="line-47"></span><span class="hs-comment">--     %m = load i32* @glob, !nontemporal !{ i32 0, !{ i32 0 } }</span><span>
</span><span id="line-48"></span><span class="hs-comment">--   Only metadata nodes or expressions can be attached, named metadata cannot.</span><span>
</span><span id="line-49"></span><span class="hs-comment">--   Refer to LLVM documentation for which instructions take metadata and its</span><span>
</span><span id="line-50"></span><span class="hs-comment">--   meaning.</span><span>
</span><span id="line-51"></span><span class="hs-comment">--</span><span>
</span><span id="line-52"></span><span class="hs-comment">-- - As arguments -- llvm functions can take metadata as arguments, for</span><span>
</span><span id="line-53"></span><span class="hs-comment">--   example:</span><span>
</span><span id="line-54"></span><span class="hs-comment">--     call void @llvm.dbg.value(metadata !{ i32 0 }, i64 0, metadata !1)</span><span>
</span><span id="line-55"></span><span class="hs-comment">--   As with instructions, only metadata nodes or expressions can be attached.</span><span>
</span><span id="line-56"></span><span class="hs-comment">--</span><span>
</span><span id="line-57"></span><span class="hs-comment">-- - As a named metadata -- Here the metadata is simply declared in global</span><span>
</span><span id="line-58"></span><span class="hs-comment">--   scope using a specific name to communicate module level information to LLVM.</span><span>
</span><span id="line-59"></span><span class="hs-comment">--   For example:</span><span>
</span><span id="line-60"></span><span class="hs-comment">--     !llvm.module.linkage = !{ !0, !1 }</span><span>
</span><span id="line-61"></span><span class="hs-comment">--</span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-comment">-- | A reference to an un-named metadata node.</span><span>
</span><span id="line-64"></span><span class="hs-keyword">newtype</span><span> </span><span id="MetaId"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-var">MetaId</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="MetaId"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-var">MetaId</span></a></span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-65"></span><span>               </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681006085"><span id="local-6989586621681006090"><span class="annot"><span class="annottext">MetaId -&gt; MetaId -&gt; Bool
(MetaId -&gt; MetaId -&gt; Bool)
-&gt; (MetaId -&gt; MetaId -&gt; Bool) -&gt; Eq MetaId
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: MetaId -&gt; MetaId -&gt; Bool
$c/= :: MetaId -&gt; MetaId -&gt; Bool
== :: MetaId -&gt; MetaId -&gt; Bool
$c== :: MetaId -&gt; MetaId -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681006052"><span id="local-6989586621681006056"><span id="local-6989586621681006060"><span id="local-6989586621681006064"><span id="local-6989586621681006068"><span id="local-6989586621681006072"><span id="local-6989586621681006077"><span class="annot"><span class="annottext">Eq MetaId
Eq MetaId
-&gt; (MetaId -&gt; MetaId -&gt; Ordering)
-&gt; (MetaId -&gt; MetaId -&gt; Bool)
-&gt; (MetaId -&gt; MetaId -&gt; Bool)
-&gt; (MetaId -&gt; MetaId -&gt; Bool)
-&gt; (MetaId -&gt; MetaId -&gt; Bool)
-&gt; (MetaId -&gt; MetaId -&gt; MetaId)
-&gt; (MetaId -&gt; MetaId -&gt; MetaId)
-&gt; Ord MetaId
MetaId -&gt; MetaId -&gt; Bool
MetaId -&gt; MetaId -&gt; Ordering
MetaId -&gt; MetaId -&gt; MetaId
forall a.
Eq a
-&gt; (a -&gt; a -&gt; Ordering)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; a)
-&gt; (a -&gt; a -&gt; a)
-&gt; Ord a
min :: MetaId -&gt; MetaId -&gt; MetaId
$cmin :: MetaId -&gt; MetaId -&gt; MetaId
max :: MetaId -&gt; MetaId -&gt; MetaId
$cmax :: MetaId -&gt; MetaId -&gt; MetaId
&gt;= :: MetaId -&gt; MetaId -&gt; Bool
$c&gt;= :: MetaId -&gt; MetaId -&gt; Bool
&gt; :: MetaId -&gt; MetaId -&gt; Bool
$c&gt; :: MetaId -&gt; MetaId -&gt; Bool
&lt;= :: MetaId -&gt; MetaId -&gt; Bool
$c&lt;= :: MetaId -&gt; MetaId -&gt; Bool
&lt; :: MetaId -&gt; MetaId -&gt; Bool
$c&lt; :: MetaId -&gt; MetaId -&gt; Bool
compare :: MetaId -&gt; MetaId -&gt; Ordering
$ccompare :: MetaId -&gt; MetaId -&gt; Ordering
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Ord</span></span></span></span></span></span></span></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681006017"><span id="local-6989586621681006021"><span id="local-6989586621681006025"><span id="local-6989586621681006029"><span id="local-6989586621681006033"><span id="local-6989586621681006037"><span id="local-6989586621681006041"><span id="local-6989586621681006046"><span class="annot"><span class="annottext">Int -&gt; MetaId
MetaId -&gt; Int
MetaId -&gt; [MetaId]
MetaId -&gt; MetaId
MetaId -&gt; MetaId -&gt; [MetaId]
MetaId -&gt; MetaId -&gt; MetaId -&gt; [MetaId]
(MetaId -&gt; MetaId)
-&gt; (MetaId -&gt; MetaId)
-&gt; (Int -&gt; MetaId)
-&gt; (MetaId -&gt; Int)
-&gt; (MetaId -&gt; [MetaId])
-&gt; (MetaId -&gt; MetaId -&gt; [MetaId])
-&gt; (MetaId -&gt; MetaId -&gt; [MetaId])
-&gt; (MetaId -&gt; MetaId -&gt; MetaId -&gt; [MetaId])
-&gt; Enum MetaId
forall a.
(a -&gt; a)
-&gt; (a -&gt; a)
-&gt; (Int -&gt; a)
-&gt; (a -&gt; Int)
-&gt; (a -&gt; [a])
-&gt; (a -&gt; a -&gt; [a])
-&gt; (a -&gt; a -&gt; [a])
-&gt; (a -&gt; a -&gt; a -&gt; [a])
-&gt; Enum a
enumFromThenTo :: MetaId -&gt; MetaId -&gt; MetaId -&gt; [MetaId]
$cenumFromThenTo :: MetaId -&gt; MetaId -&gt; MetaId -&gt; [MetaId]
enumFromTo :: MetaId -&gt; MetaId -&gt; [MetaId]
$cenumFromTo :: MetaId -&gt; MetaId -&gt; [MetaId]
enumFromThen :: MetaId -&gt; MetaId -&gt; [MetaId]
$cenumFromThen :: MetaId -&gt; MetaId -&gt; [MetaId]
enumFrom :: MetaId -&gt; [MetaId]
$cenumFrom :: MetaId -&gt; [MetaId]
fromEnum :: MetaId -&gt; Int
$cfromEnum :: MetaId -&gt; Int
toEnum :: Int -&gt; MetaId
$ctoEnum :: Int -&gt; MetaId
pred :: MetaId -&gt; MetaId
$cpred :: MetaId -&gt; MetaId
succ :: MetaId -&gt; MetaId
$csucc :: MetaId -&gt; MetaId
</span><a href="../../base/src/GHC.Enum.html#Enum"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Enum</span></a></span></span></span></span></span></span></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621681006010"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-type">MetaId</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-68"></span><span>    </span><span id="local-6989586621681006008"><span class="annot"><span class="annottext">ppr :: MetaId -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-type">MetaId</span></a></span><span> </span><span id="local-6989586621681006006"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621681006006"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Char -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#char"><span class="hs-identifier hs-var">char</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'!'</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#int"><span class="hs-identifier hs-var">int</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621681006006"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span class="hs-comment">-- | LLVM metadata expressions</span><span>
</span><span id="line-71"></span><span class="hs-keyword">data</span><span> </span><span id="MetaExpr"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaExpr"><span class="hs-identifier hs-var">MetaExpr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="MetaStr"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaStr"><span class="hs-identifier hs-var">MetaStr</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Llvm.Types.html#LMString"><span class="hs-identifier hs-type">LMString</span></a></span><span>
</span><span id="line-72"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span id="MetaNode"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaNode"><span class="hs-identifier hs-var">MetaNode</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-type">MetaId</span></a></span><span>
</span><span id="line-73"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span id="MetaVar"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaVar"><span class="hs-identifier hs-var">MetaVar</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Llvm.Types.html#LlvmVar"><span class="hs-identifier hs-type">LlvmVar</span></a></span><span>
</span><span id="line-74"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span id="MetaStruct"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaStruct"><span class="hs-identifier hs-var">MetaStruct</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaExpr"><span class="hs-identifier hs-type">MetaExpr</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-75"></span><span>              </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681005987"><span id="local-6989586621681005997"><span class="annot"><span class="annottext">MetaExpr -&gt; MetaExpr -&gt; Bool
(MetaExpr -&gt; MetaExpr -&gt; Bool)
-&gt; (MetaExpr -&gt; MetaExpr -&gt; Bool) -&gt; Eq MetaExpr
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: MetaExpr -&gt; MetaExpr -&gt; Bool
$c/= :: MetaExpr -&gt; MetaExpr -&gt; Bool
== :: MetaExpr -&gt; MetaExpr -&gt; Bool
$c== :: MetaExpr -&gt; MetaExpr -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-comment">-- | Associates some metadata with a specific label for attaching to an</span><span>
</span><span id="line-78"></span><span class="hs-comment">-- instruction.</span><span>
</span><span id="line-79"></span><span class="hs-keyword">data</span><span> </span><span id="MetaAnnot"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaAnnot"><span class="hs-identifier hs-var">MetaAnnot</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="MetaAnnot"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaAnnot"><span class="hs-identifier hs-var">MetaAnnot</span></a></span></span><span> </span><span class="annot"><a href="GHC.Llvm.Types.html#LMString"><span class="hs-identifier hs-type">LMString</span></a></span><span> </span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaExpr"><span class="hs-identifier hs-type">MetaExpr</span></a></span><span>
</span><span id="line-80"></span><span>               </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681005980"><span id="local-6989586621681005984"><span class="annot"><span class="annottext">MetaAnnot -&gt; MetaAnnot -&gt; Bool
(MetaAnnot -&gt; MetaAnnot -&gt; Bool)
-&gt; (MetaAnnot -&gt; MetaAnnot -&gt; Bool) -&gt; Eq MetaAnnot
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: MetaAnnot -&gt; MetaAnnot -&gt; Bool
$c/= :: MetaAnnot -&gt; MetaAnnot -&gt; Bool
== :: MetaAnnot -&gt; MetaAnnot -&gt; Bool
$c== :: MetaAnnot -&gt; MetaAnnot -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span class="hs-comment">-- | Metadata declarations. Metadata can only be declared in global scope.</span><span>
</span><span id="line-83"></span><span class="hs-keyword">data</span><span> </span><span id="MetaDecl"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaDecl"><span class="hs-identifier hs-var">MetaDecl</span></a></span></span><span>
</span><span id="line-84"></span><span>    </span><span class="hs-comment">-- | Named metadata. Only used for communicating module information to</span><span>
</span><span id="line-85"></span><span>    </span><span class="hs-comment">-- LLVM. ('!name = !{ [!\&lt;n&gt;] }' form).</span><span>
</span><span id="line-86"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span id="MetaNamed"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaNamed"><span class="hs-identifier hs-var">MetaNamed</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Llvm.Types.html#LMString"><span class="hs-identifier hs-type">LMString</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-type">MetaId</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-comment">-- | Metadata node declaration.</span><span>
</span><span id="line-88"></span><span>    </span><span class="hs-comment">-- ('!0 = metadata !{ \&lt;metadata expression&gt; }' form).</span><span>
</span><span id="line-89"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span id="MetaUnnamed"><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaUnnamed"><span class="hs-identifier hs-var">MetaUnnamed</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaId"><span class="hs-identifier hs-type">MetaId</span></a></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Llvm.MetaData.html#MetaExpr"><span class="hs-identifier hs-type">MetaExpr</span></a></span><span>
</span><span id="line-90"></span></pre></body></html>